Skip to content

Add Paykit integration module (Phase 3.1)#524

Closed
BitcoinErrorLog wants to merge 2 commits into
masterfrom
paykit-integration-phase3
Closed

Add Paykit integration module (Phase 3.1)#524
BitcoinErrorLog wants to merge 2 commits into
masterfrom
paykit-integration-phase3

Conversation

@BitcoinErrorLog

Copy link
Copy Markdown
Contributor

Summary

This PR implements the core Paykit integration module for Bitkit Android:

  • PaykitManager: Singleton managing PaykitClient lifecycle and executor registration. Maps LDK Network to Paykit network configs (MAINNET/TESTNET/REGTEST/SIGNET). Uses Mutex for thread-safe coroutine initialization.

  • BitkitBitcoinExecutor: Implements BitcoinExecutorFFI, bridging LightningRepo.sendOnChain() to Paykit's onchain payment interface. Uses runBlocking(Dispatchers.IO) with withTimeout for coroutine-to-sync FFI bridging.

  • BitkitLightningExecutor: Implements LightningExecutorFFI, bridging LightningRepo.payInvoice() to Paykit. Includes payment completion polling via getPayments(), SHA-256 preimage verification, and hex encoding utilities.

  • PaykitIntegrationHelper: Convenience methods for setup and payment execution, with both suspend and callback-based async APIs.

Key Features

  1. Network Configuration Mapping: Automatically maps Bitkit's Env.network to Paykit's network enums
  2. Coroutine-to-Sync Bridging: Uses runBlocking with Dispatchers.IO and timeouts for sync FFI calls
  3. Payment Completion Polling: Polls LightningRepo.getPayments() to retrieve payment status and preimage
  4. Thread Safety: Uses Kotlin Mutex for thread-safe initialization
  5. Dagger/Hilt Compatible: PaykitManager annotated with @Singleton and @Inject

Prerequisites

PaykitMobile UniFFI bindings must be generated and linked before these components are fully functional. TODOs in the code mark where binding code should be uncommented.

Test plan

  • Generate PaykitMobile bindings with cargo build --features mobile
  • Add jniLibs to Gradle configuration
  • Uncomment FFI binding code in PaykitManager and executors
  • Test PaykitIntegrationHelper.setup(lightningRepo) during app startup
  • Verify Lightning payments return preimage proof
  • Verify onchain payments return txid

JOHN added 2 commits December 14, 2025 17:47
- Document LightningRepo and WalletRepo integration points
- Map Paykit executor methods to Bitkit APIs
- Document suspend/sync bridging patterns
- Document error handling with Result<T> pattern
- Document network configuration mapping
- Outline payment completion polling strategy
- Document dependency injection setup
Implements the core Paykit integration components:

- PaykitManager: Singleton managing PaykitClient lifecycle and executor
  registration. Maps LDK Network to Paykit network configs. Uses Mutex
  for thread-safe initialization.

- BitkitBitcoinExecutor: Implements BitcoinExecutorFFI, bridging
  LightningRepo.sendOnChain() to Paykit's onchain payment interface.
  Uses runBlocking with Dispatchers.IO for coroutine-to-sync bridging.

- BitkitLightningExecutor: Implements LightningExecutorFFI, bridging
  LightningRepo.payInvoice() to Paykit. Includes payment completion
  polling to extract preimage proof, SHA-256 verification.

- PaykitIntegrationHelper: Convenience methods for setup and payment
  execution with async callback support.

Note: PaykitMobile bindings (UniFFI generated) must be linked before
these components are fully functional. TODOs mark where binding code
should be uncommented once available.

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detekt found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants